package com.applications.codemash.core.eventhandlers;

import com.applications.codemash.SessionInfo;
import com.applications.codemash.core.Constants;
import com.applications.codemash.core.Session;
import com.applications.codemash.utility.CustomListAdapter;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class ListViewItemClickListener implements OnItemClickListener
{
	private Activity _activity;
	
	public ListViewItemClickListener(Activity activity)
	{
		_activity = activity;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public void onItemClick(AdapterView<?> parentView, View view, int position, long arg3)
	{
		((ListView)parentView).setSelection(position);
		Session session = ((CustomListAdapter<Session>)parentView.getAdapter()).getData().get(position);
		Intent myIntent = new Intent(view.getContext(), SessionInfo.class);
		myIntent.putExtra(Constants.SESSION_INTENT_KEY, session);
		
		_activity.startActivityForResult(myIntent, 0);
		return;
	}
}
